#!/bin/bash
#perf stat for branch information

br_inst_exec_events=(
    "br_inst_exec.all_branches"
    "br_inst_exec.all_conditional"
    "br_inst_exec.all_direct_jmp"
    "br_inst_exec.all_direct_near_call"
    "br_inst_exec.all_indirect_jump_non_call_ret"
    "br_inst_exec.all_indirect_near_return"
    "br_inst_exec.nontaken_conditional"
    "br_inst_exec.taken_conditional"
    "br_inst_exec.taken_direct_jump"
    "br_inst_exec.taken_direct_near_call"
    "br_inst_exec.taken_indirect_jump_non_call_ret"
    "br_inst_exec.taken_indirect_near_call"
    "br_inst_exec.taken_indirect_near_return"
)

br_inst_retired_events=(
    "br_inst_retired.all_branches"
    "br_inst_retired.conditional"
    "br_inst_retired.far_branch"
    "br_inst_retired.near_call"
    "br_inst_retired.near_return"
    "br_inst_retired.near_taken"
    "br_inst_retired.not_taken"
)

br_misp_events=(
    "br_misp_exec.all_branches"                         
    "br_misp_exec.all_conditional"                     
    "br_misp_exec.all_indirect_jump_non_call_ret"       
    "br_misp_exec.nontaken_conditional"                 
    "br_misp_exec.taken_conditional"                    
    "br_misp_exec.taken_indirect_jump_non_call_ret"     
    "br_misp_exec.taken_indirect_near_call"             
    "br_misp_exec.taken_return_near"
)


branch_hardware_events=(
	"branches"
	"branch-misses"
    "branch-loads"
	"branch-load-misses"
)

events=(${branch_hardware_events[*]}) #${br_inst_exec_events[*]} ${br_misp_events[*]} ${br_inst_retired_events[*]})

#group_events="-M IPC,ILP,MLP,UPI,CPU_Utilization,Kernel_Utilization"
group_events="" #"-M IPC,ILP,MLP,UPI,CPU_Utilization,Kernel_Utilization"
eventlist="instructions"
for e in ${events[@]};
do
    eventlist=$eventlist","$e
done

perfcmds="perf stat -e "
echo $*

time=$(date "+%m-%d-%H-%M-%S")
echo $time

${perfcmds} $eventlist $group_events $* 

time=$(date "+%m-%d-%H-%M-%S")
echo $time
# ${perfcmds} $eventlist $* | tee "branch-$time".log


